package com.itheimaoa.web.action;

import java.io.FileInputStream;
import java.util.zip.ZipInputStream;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;
import org.jbpm.api.ProcessEngine;
import org.jbpm.api.ProcessInstance;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;

@Controller("initAction")
@Scope("prototype")
public class InitAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Resource
	private ProcessEngine processEngine;

	public String init() throws Exception {
		String path=ServletActionContext.getServletContext().getRealPath("/WEB-INF/classes/jbpm/task.zip");
		ZipInputStream zis = new ZipInputStream(new FileInputStream(path));
		processEngine.getRepositoryService().createDeployment().addResourcesFromZipInputStream(zis).deploy();
/*		Map<String, String> map = new HashMap<String, String>();
		map.put("customerId", "001");
		processEngine.getExecutionService().startProcessInstanceByKey("task", map);*/
		return "init";
	}

	public String end() {
		processEngine.getExecutionService().endProcessInstance("itheimaTask.9", ProcessInstance.STATE_ENDED);
		return "init";
	}
}
